<template>
    <div class="goods-list">

        <!--在网页中有两种跳转方式:1.使用a标签 2.使用window.location.href 也就是编程式导航-->
        <div class="goods-item" v-for="item in goodslist" :key="item.ticket_typeid" @click="goDetail(item.ticket_typeid)">
            <img :src="item.url" alt="">
            <h1 class="title">{{item.ticket_typename}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">¥{{item.price}}</span>
                </p>
                <p class="sell">
                    <span>订票接受中</span>
                    <span>剩{{item.amount}}件</span>
                </p>
            </div>
        </div>

        <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>

    </div>
</template>

<script>
    export default {
        data(){
            return{
                pageindex:1,
                goodslist:[]
            }
        },
        created(){this.getGoodList();},
        methods:{
            getGoodList(){
                //    根据分类ID获取图片列表
                this.$http.get('ticketList').then(result=>{
                        this.goodslist = this.goodslist.concat(result.body);
                })
            },
            getMore(){
                this.pageindex++;
                this.getGoodList();
            },
            goDetail(id){   //使用JS的形式进行路由导航
                //区分route和router:route是路由参数对象 所有路由中的参数都属于它; router是路由导航对象 用它可以方便地使用js代码实现路由的前进后腿来进行地址跳转
                //1.最简单的
                // this.$router.push('/home/goodsinfo/'+id);
                //2.传递对象
                // this.$router.push({path: '/home/goodsinfo/' + id});
                //3.传递命名的路由
                this.$router.push({name:'goodsinfo', params: {id}});
            }
        },
    }
</script>

<style lang="scss" scoped>
    .goods-list{
        display: flex;
        flex-wrap: wrap;
        justify-content:space-between;
        padding:8px;
        .goods-item{
            width:49%;
            border: 1px solid #ccc;
            box-shadow:0 0 8px #ccc;
            margin:4px 0;
            padding:2px;
            display: flex;
            flex-direction:column;
            justify-content:space-between;
            min-height:293px;
            img{
                width:100%;
            }
        }
        .title{
            font-size:14px;
        }
        .info{
            background-color: #eee;
            p{
                margin:0;
                padding:5px;
            }
            .price{
                .now{
                    color:red;
                    font-weight:bold;
                    font-size:16px;
                    }
                .old{
                    text-decoration: line-through;
                    font-size:12px;
                    margin-left:10px;
                }
            }
            .sell{
                display:flex;
                justify-content: space-between;
                font-size:13px;
            }
        }
    }
</style>